package com.guet.issue.controller;

import com.guet.common.entity.PageDataVO;
import com.guet.common.response.ResultCodeEnum;
import com.guet.common.response.ResultVO;
import com.guet.issue.beans.entity.Issue;
import com.guet.issue.beans.vo.IssueDateVO;
import com.guet.issue.service.IIssueService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author Li
 * @create 2022-12-16-21:47
 */
@RestController
@RequestMapping("/issue")
public class IssueController {

    @Autowired
    IIssueService issueService;

    @RequestMapping("/addIssue")
    public ResultVO add(@RequestParam String newIssue,@RequestParam Integer userId){

        issueService.add(newIssue, userId);

        return new ResultVO<>(ResultCodeEnum.SUCCESS);
    }

    @RequestMapping("/deleteIssue")
    public ResultVO delete(@RequestParam Integer id){

        issueService.delete(id);

        return new ResultVO<>(ResultCodeEnum.SUCCESS);
    }

    @RequestMapping("/pageIssue")
    public ResultVO<PageDataVO<Issue>> select(Integer userId, String keyWord, Integer pageSize, Integer pageNum){
        PageDataVO<Issue> pageDataVO = issueService.select(userId, keyWord, pageSize, pageNum);

        return new ResultVO<>(ResultCodeEnum.SUCCESS, pageDataVO);

    }

    @RequestMapping("/select")
    public ResultVO<IssueDateVO> select(@RequestParam Integer userId, @RequestParam Integer issueId){

        IssueDateVO issueDateVO = issueService.selectIssueAndCommentAndUpsum(userId, issueId);

        return new ResultVO<>(ResultCodeEnum.SUCCESS, issueDateVO);

    }








}
